package com.jadobo.xswing.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.jadobo.xswing.model.IElement;

public class Elem {

	/**
	 * Traverse tree of element to get all element as single collection.
	 * 
	 * @param elements
	 * @return
	 */
	public static List<IElement> getAllElements(List<IElement> elements) {
		
		if(elements == null || elements.isEmpty()) {
			return Collections.emptyList();
		}
		
		List<IElement> list = new ArrayList<IElement>();
		
		for(IElement element : elements) {
			list.addAll(getAllElements(element));
		}
		
		return list;
	}

	/**
	 * Traverse tree of element to get all element as single collection.
	 * 
	 * @param element
	 * @return
	 */
	public static List<IElement> getAllElements(
			IElement element) {
		
		if(element == null) {
			return Collections.emptyList();
		}

		List<IElement> list = new ArrayList<IElement>();
		
		list.add(element);
		
		list.addAll(getAllElements(element.getElements()));
		
		
		return list;
	}
}
